function palmResourceContainer(){
}

palmResourceContainer.prototype.parseFile=function(filePath){
	if(filePath!=undefined && filePath!="" && filePath!=false) inputStream=new fileReaderUtility(filePath);
	
	this.prcFileName=filePath;

	
	prcObject={};
	prcObject["name"]=inputStream.fgets();
	
	inputStream.fseek(0x20);
	prcObject["flags"]=inputStream.fget16be();	
	prcObject["version"]=inputStream.fget16be();	
	prcObject["timecreate"]=inputStream.fget32be();	
	prcObject["timemod"]=inputStream.fget32be();			
	prcObject["timebackup"]=inputStream.fget32be();		
	prcObject["modnum"]=inputStream.fget32be();	
	prcObject["appinfo"]=inputStream.fget32be();	
	prcObject["sortinfo"]=inputStream.fget32be();	
	prcObject["type"]=inputStream.fgetsl(4);
	prcObject["creator"]=inputStream.fgetsl(4);		
	prcObject["idseed"]=inputStream.fget32be();
	prcObject["nextreclist"]=inputStream.fget32be();
	prcObject["numrecs"]=inputStream.fget16be();
	
	prcObject["recs"]=new Array();		
	for(var i=0;i<prcObject["numrecs"];i++){
		prcObject["recs"][i]={};
		prcObject["recs"][i]["type"]=inputStream.fgetsl(4);
		prcObject["recs"][i]["id"]=inputStream.fget16be();
		prcObject["recs"][i]["offset"]=inputStream.fget32be();
		
		if(i>0){
				prcObject["recs"][i-1]["size"]=prcObject["recs"][i]["offset"]-prcObject["recs"][i-1]["offset"];
		}
	}
	
	if(prcObject["numrecs"]>0)
		prcObject["recs"][prcObject["numrecs"]-1]["size"]=inputStream.fileobject.fileSize-prcObject["recs"][prcObject["numrecs"]-1]["offset"];
	
	inputStream.fclose();
	this.prcInfo=prcObject;
}
	
palmResourceContainer.prototype.setup=function(){
	if(this.XULlist==undefined){
		XULColumns=new Array();
		XULColumns[0]={"label":constants.strings.UI.prcList.labelType, "id":"XULPRCListType", "flex":"1"};
		XULColumns[1]={"label":constants.strings.UI.prcList.labelId, "id":"XULPRCListId", "flex":"1"};
		XULColumns[2]={"label":constants.strings.UI.prcList.labelOffset, "id":"XULPRCListOffset", "flex":"1"};
		XULColumns[3]={"label":constants.strings.UI.prcList.labelSize, "id":"XULPRCListSize", "flex":"1"};
		
		this.XULlist=new XULassociatedList(document.getElementById("prcResListParent"),XULColumns,"PRCFileResourceList",UI_action );
		
		XULLabels=new Array(
			constants.strings.UI.prcFileInfo.name,
			constants.strings.UI.prcFileInfo.flags,
			constants.strings.UI.prcFileInfo.ver,
			constants.strings.UI.prcFileInfo.ctime,
			constants.strings.UI.prcFileInfo.mtime,
			constants.strings.UI.prcFileInfo.btime,
			constants.strings.UI.prcFileInfo.appinfo,
			constants.strings.UI.prcFileInfo.sortinfo,
			constants.strings.UI.prcFileInfo.type,
			constants.strings.UI.prcFileInfo.creator,
			constants.strings.UI.prcFileInfo.idseed,
			constants.strings.UI.prcFileInfo.nextrec,
			constants.strings.UI.prcFileInfo.numrecs
		);
		
		this.XULProperties=new XULassociatedNameValueGrid(document.getElementById("propertyListParent"),XULLabels);
	}
	
}

palmResourceContainer.prototype.applyPRCInfo=function(){
	dataArray=new Array();
	for(var i=0;i<this.prcInfo["recs"].length;i++){
		dataArray[i]=new Array();
		dataArray[i][0]=this.prcInfo["recs"][i]["type"];
		dataArray[i][1]=this.prcInfo["recs"][i]["id"];
		dataArray[i][2]=this.prcInfo["recs"][i]["offset"];
		dataArray[i][3]=this.prcInfo["recs"][i]["size"];
	}
	this.XULlist.applyList(dataArray);
}

palmResourceContainer.prototype.readEntry=function(index,viewtype){
	inputStream=new fileReaderUtility(this.prcFileName);
	inputStream.fseek(parseInt(this.prcInfo["recs"][index]["offset"]));
	
	l=parseInt(this.prcInfo["recs"][index]["size"]);
	
	v="";
	n=viewtype;
	p=0;
	r=inputStream.binarystream.read8;
	t=String.fromCharCode;
	m=Math.floor;
	
	q=(n==0);
	s=(n==2);
	//Padding?
	u=(q||s);

	f=(u?" ":"");
	for(var i=0;i<l;i++){
		c=r();
		if(((c>=0x20 && c<0x7F) ||  c==0x0a) && !s){
			switch(c){
				case 0x20: v=v+f+"_"+f+f; p+=(u?4:1); break;
				case 0x5c: v=v+f+"\\\\"+f; p+=(u?4:2); break;
				case 0x5f: v=v+f+"\\_"+f; p+=(u?4:2); break;
				case 0x25:	v=v+f+"\\%"+f; p+=(u?4:2); break;
				case 0x0a:	v=v+f+"\\n"+f; if(u)p+=4; else {v=v+"\n";p=0;} break;					
				default: v=v+f+t(c)+f+f;p+=(u?4:1); break;
			}
		}else{
			x=m(c/16); y=c%16;
			if(x>9) v=v+"%"+t(0x41+(x%10));  else v=v+"%"+t(0x30 + x);
			if(y>9) v=v+t(0x41+(y%10))+f;  else v=v+t(0x30 + y)+f;
			p+=(u?4:3);
		}
		if(p>=31) {v=v+"\n"; p=0;}
	}

	inputStream.fclose();
	return v;
}

palmResourceContainer.prototype.load=function(path){
	if(path==undefined){
		utilityJSInstance=new utilityJS();
		fileObj=utilityJSInstance.fileSelect("modeLoad",constants.strings.UI.loadTitle);
		if(fileObj==undefined){ this.XULlist.clear(); return -1; }
		path=fileObj.path;
	}
	this.parseFile(path);
	this.applyPRCInfo();
}